<?php if ( ! defined('root_dir')) exit('No direct script access allowed');

/**
 * Class Name : Template
 * Use to better load Views
 * 
 * @author Ervin R. Musngi <ervinmusngi@gmail.com>
 * @copyright Copyright (c) 2011
 */
class Template {
    
    /**
     *
     * @var String $defaultTemplate;
     */
    protected  $defaultTemplate;
    
    /**
     *
     * @var NET-CORE-TECH Framework Instance
     */
    private $_nct;
    
    protected $templateConfig;
    
    protected $panels = array();
    
    public  function __construct()
    {
        $this->_nct =& get_instance();
        
        //$this->_nct->config->load('template');
        $this->_nct->config->load('facebook');
        
        //$this->defaultTemplate = $this->_nct->config->item('default_template');
                
    }

    public function setDefaultTemplate( $defaultTemplate = 'default' )
    {
        $this->defaultTemplate = $defaultTemplate;        
    }
    
    public function set( $key = '' , $value = '' , $data = array())
    {
        $this->panels[$key] = $this->_nct->loadView($value,$data,true);
    }
    
    public function css( $cssFile = '' )
    {
        if ( file_exists( base_url().'application/template/'.$this->defaultTemplate.'/css/'.$cssFile.'.css' ) )
        {
            $this->panels['headers'][] = '<link rel="stylesheet" src="'.base_url().'application/template/'.$this->defaultTemplate.'/css/'.$cssFile.'.css'.'" />';
        }
    }
    
    public function js( $jsFile = '' )
    {
        if ( file_exists( base_url().'application/template/'.$this->defaultTemplate.'/js/'.$jsFile.'.js' ) )
        {
            $this->panels['headers'][] = '<script type="text/javascript" href="'.base_url().'application/template/'.$this->defaultTemplate.'/js/'.$jsFile.'.js'.'" />';
        }
    }
    
    public function render( $view = '' )
    {
        $d = array();
        
        foreach ( $this->panels as $k=>$v )
        {
            $d[$k]  = $v;
        }
        
    }
    
}
